# signals.py
from ocms.eventmanager.models import *
from django.template.loader import render_to_string
from django.core.mail import EmailMessage
from django.template import Context, loader, RequestContext
from django.conf import settings

def comment_notifier(sender, comment, **kwargs):

    event = comment.content_object
    
    planner_names = None
    planner_emails = []
    for planner in event.planning_team.all():
        planner_names = str(planner.first_name) + ", "
        planner_emails.append(str(planner.email))
    
    planner_emails.append(settings.GCC_EMAIL)
    
    
    subject = "[OCMS] New Comment on \""+str(event.Name)+"\""
    template = 'comments/notification_email.txt'
    context = Context({
            'event': event,
            'comment_user':comment.user_name,
            'planner_names': planner_names,
            'comment': comment,
            })
    t = loader.get_template(template)
    body = t.render(context)

    msg = EmailMessage(subject, body, 'OWASP Event System <conference@owasp.org>',planner_emails)
    msg.send()
